<?php 
  /**
   * @author claudiugh
   */

require_once('includes/PT_MapPoint.class.php');
require_once('includes/PT_MapNode.class.php');
require_once('includes/PT_Graph.class.php');
require_once('includes/util.class.php');

$graf = new PT_Graph();

/*****************************************/
// load data 
require_once('ptroute.in.php');
$graf->add_network($retea_metrou);
$graf->add_network($retea_tramvai);


/*****************************************/
// load input 

// hardcoded input - for debug 
// $_POST['JSONRequest'] = '{\"source_lat\":44.445631,\"source_lon\":26.050657,\"dest_lat\":44.378695,\"dest_lon\":26.218134}';

$input_data = json_decode(stripslashes($_POST['JSONRequest']));
$src = new PT_MapPoint($input_data->source_lat,
		       $input_data->source_lon);
$dst = new PT_MapPoint($input_data->dest_lat,
		       $input_data->dest_lon);

Util::log(basename(__FILE__) . '['.__LINE__.']',
	  print_r($src, true));
Util::log(basename(__FILE__) . '['.__LINE__.']',
	  print_r($dst, true));

$ruta = $graf->find_route($src, $dst);

if ($ruta === FALSE)
  echo "Nu exista ruta";
 else
   {
     $raspuns = $graf->map_road($ruta);
     echo json_encode($raspuns);
   }

?>